# 导入库

import pdfkit
from bs4 import BeautifulSoup
html_path = 'E:\\code\\java_code\\IdeaProjects\\Hello_world\\src\\test.html'


pass
path_wkthmltopdf = r'D:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe'
'''将html文件生成pdf文件'''
def html_to_pdf(html, to_file):
    # 将wkhtmltopdf.exe程序绝对路径传入config对象

    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
    # 生成pdf文件，to_file为文件路径
    pdfkit.from_file(html, to_file, configuration=config)
    print('完成')

html_to_pdf('generate.html','name.pdf')
# # 导入库
# import pdfkit
#
# '''将网页url生成pdf文件'''
# def url_to_pdf(url, to_file):
#     # 将wkhtmltopdf.exe程序绝对路径传入config对象
#
#     config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
#     # 生成pdf文件，to_file为文件路径
#     pdfkit.from_url(url, to_file, configuration=config)
#     print('完成')
#
# # 这里传入我知乎专栏文章url，转换为pdf
# url_to_pdf(r'https://blog.csdn.net/weixin_38924500/article/details/104767891', 'name.pdf')  #第二个为文件地址及命名   ./PDF/文件名.pdf
# from html.parser import HTMLParser
#
#
# class Parse(HTMLParser):
#     def __init__(self):
#         # Since Python 3, we need to call the __init__() function
#         # of the parent class
#         super().__init__()
#         self.reset()
#
#     # Defining what the methods should output when called by HTMLParser.
#     def handle_starttag(self, tag, attrs):
#         print("Start tag: ", tag)
#         for a in attrs:
#             print("Attributes of the tag: ", a)
#
#     def handle_data(self, data):
#         print("Here's the data: ", data)
#
#     def handle_endtag(self, tag):
#         print("End tag: ", tag)
#
#
# with open(html_path,mode='r',encoding='utf-8') as html_file:
#     html_content = html_file.read()
#     soup = BeautifulSoup(html_content, 'html.parser')
#     pass
# pass
